package lec07.pm;

import java.util.Iterator;
import java.util.LinkedList;

public class CycListDemo {
	public static void main(String[] args) {
		LinkedList<Integer> list = new LinkedList<Integer>();
		for (int i = 1; i <= 5; i++)
			list.add(i);
		System.out.println(list);
		Iterator<Integer> it = list.iterator();
		int i = 0;
		while (list.size() > 1) {
			if (it.hasNext()) {
				it.next();
				i++;
				if (i % 2 == 0)
					it.remove();
			} else {
				it = list.iterator();
			}
		}
		System.out.println(list);
	}
}
